﻿<UserControl x:Class="LayoutWindow.Views.LayoutView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:b="clr-namespace:LayoutWindow.Behaviors"
             xmlns:conv="clr-namespace:LayoutWindow.Converters"
             mc:Ignorable="d" 
             d:DesignHeight="100" d:DesignWidth="300">
    <UserControl.Resources>
        <conv:TypeNameConverter x:Key="conv"/>
        <conv:NullToVisibilityConverter x:Key="visConv"/>
        <DataTemplate x:Key="treeHeaderTemplate">
            <StackPanel Orientation="Horizontal">
                <TextBlock Text="{Binding Path=Name}"/>
                <TextBlock Text="{Binding Converter={StaticResource conv}}"/>
            </StackPanel>
        </DataTemplate>
        <HierarchicalDataTemplate x:Key="treeItemTemplate" ItemsSource="{Binding Fields}">
            <StackPanel Orientation="Horizontal">
                <TextBlock Text="{Binding Path=Name}"/>
                <TextBlock Text="{Binding Converter={StaticResource conv}}"/>
            </StackPanel>
        </HierarchicalDataTemplate>
        
        <RectangleGeometry x:Key="delGeom" Rect="0,10,30,10" />
        <CombinedGeometry x:Key="addGeom" GeometryCombineMode="Union">
            <CombinedGeometry.Geometry1>
                <RectangleGeometry Rect="0,20,30,10"/>
            </CombinedGeometry.Geometry1>
            <CombinedGeometry.Geometry2>
                <RectangleGeometry Rect="10,10,10,30" />
            </CombinedGeometry.Geometry2>
        </CombinedGeometry>
        <Path x:Key="addPath" Data="{StaticResource addGeom}" Fill="Green" Width="10" Stretch="Uniform"></Path>
        <Path x:Key="delPath" Data="{StaticResource delGeom}" Fill="Red" Width="10" Stretch="Uniform"></Path>
        
        <Style TargetType="{x:Type Button}">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type Button}">
                        <Border x:Name="border">
                            <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                              VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                        </Border>
                        <ControlTemplate.Triggers>
                            <MultiTrigger>
                                <MultiTrigger.Conditions>
                                    <Condition  Property="IsMouseOver" Value="True"/>
                                    <Condition  Property="IsEnabled" Value="False"/>
                                </MultiTrigger.Conditions>
                                <Setter Property="Background" Value="LightGoldenrodYellow" TargetName="border"/>
                            </MultiTrigger>
                            <MultiTrigger>
                                <MultiTrigger.Conditions>
                                    <Condition  Property="IsPressed" Value="True"/>
                                    <Condition  Property="IsEnabled" Value="False"/>
                                </MultiTrigger.Conditions>
                                <Setter Property="Background" Value="LightYellow" TargetName="border"/>
                            </MultiTrigger>
                            
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </UserControl.Resources>
    <Grid Background="WhiteSmoke">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <Border Background="DarkBlue">
            <TextBlock Text="Layout View" Foreground="White"
                       Margin="5,2" FontWeight="Bold"/>
        </Border>
        <Grid Grid.Row="1">
            <ToolBar >
                <Button Content="{StaticResource addPath}" Command="{Binding Path=AddCommand}"/>
                <Button Content="{StaticResource delPath}" Command="{Binding Path=DeleteCommand}"/>
                <Separator/>
                <Button Content="U" Command="{Binding Path=UpCommand}" />
                <Button Content="D" Command="{Binding Path=DownCommand}"/>
                <Separator/>
                <Button Content="B" Command="{Binding Path=AddBannerCommand}" />
                <Button Content="T" Command="{Binding Path=AddTitleCommand}" />
                <Button Content="S" Command="{Binding Path=AddStatusCommand}"/>
                <!--<Separator/>
                <Button Content="{Binding ExpandedString}" Command="{Binding Path=ExpandCommand}"/>-->
            </ToolBar>
        </Grid>
        <Grid Grid.Row="2">
            <TreeView BorderBrush="Transparent" BorderThickness="0"
                              b:TreeSelect.Command="{Binding Path=SelectedCommand}"
                              b:TreeSelect.CommandParameter="{Binding Path=SelectedItem, RelativeSource={RelativeSource Mode=Self}}"
                      Visibility="{Binding Converter={StaticResource visConv}}"
                      >
                <TreeViewItem Header="Banner"
                              ItemsSource="{Binding Banner}"
                              ItemTemplate="{StaticResource treeItemTemplate}"
                              >
                </TreeViewItem>
                <TreeViewItem Header="Title"
                              ItemsSource="{Binding Title}"
                              ItemTemplate="{StaticResource treeItemTemplate}"
                              >
                </TreeViewItem>
                <TreeViewItem Header="Fields"
                              ItemsSource="{Binding Screen.Fields}"
                              ItemTemplate="{StaticResource treeItemTemplate}"
                              >
                </TreeViewItem>
                <TreeViewItem Header="Status"
                              ItemsSource="{Binding Status}"
                              ItemTemplate="{StaticResource treeItemTemplate}"
                              >
                </TreeViewItem>
                <TreeView.ItemContainerStyle>
                    <Style TargetType="{x:Type TreeViewItem}">
                        <Setter Property="IsExpanded" Value="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type TreeView}}, Path=DataContext.IsExpanded, Mode=OneWay}"/>
                    </Style>
                </TreeView.ItemContainerStyle>
            </TreeView>
            <!--<TreeView Grid.Row="2" ItemsSource="{Binding Path=Screen.Fields}"
                      ItemTemplate="{StaticResource treeItemTemplate}"
                  b:TreeSelect.Command="{Binding Path=SelectedCommand}"
                  b:TreeSelect.CommandParameter="{Binding Path=SelectedItem, RelativeSource={RelativeSource Mode=Self}}"
                   BorderBrush="Transparent" BorderThickness="0"
                      >
                
                <TreeView.ItemContainerStyle>
                    <Style TargetType="{x:Type TreeViewItem}">
                        <Setter Property="IsExpanded" Value="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type TreeView}}, Path=DataContext.IsExpanded}"/>
                    </Style>
                </TreeView.ItemContainerStyle>
            </TreeView>-->
        </Grid>
        
    </Grid>
</UserControl>
